
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

import time


import sys

url = sys.argv[1]

driver = webdriver.Firefox()
driver.get(url)

time.sleep(7)

try:
    element = driver.find_element(By.XPATH, """html/body/c-wiz/div/div/div/div[2]/div[1]/div[3]/div[1]/form[2]/div/div/button""")
    element.click()

except:
    element = driver.find_element(By.XPATH, """/html/body/ytd-app/ytd-consent-bump-v2-lightbox/tp-yt-paper-dialog/div[4]/div/div[6]/div[1]/ytd-button-renderer[2]""")
    element.click()

time.sleep(10)


try:
    element = driver.find_element(By.XPATH, """/html/body/ytd-app/div[1]/ytd-page-manager/ytd-watch-flexy/div[5]/div[1]/div/div[6]/div[1]/div[2]/ytd-video-primary-info-rinfo-renderer/div/div/div[3]/div/ytd-menu-renderer/yt-icon-button/button/yt-icon""")
    element.click()
    time.sleep(5)


except:
    element = driver.find_element(By.CSS_SELECTOR, """ytd-menu-renderer.ytd-video-primary-info-renderer > yt-icon-button:nth-child(3) > button:nth-child(1)""")
    element.click()

    time.sleep(5)


element = driver.find_element(By.XPATH, """/html/body/ytd-app/ytd-popup-container/tp-yt-iron-dropdown/div/ytd-menu-popup-renderer/tp-yt-paper-listbox/ytd-menu-service-item-renderer/tp-yt-paper-item""")
element.click()
time.sleep(10)

try:
    element = driver.find_element(By.XPATH, """/html/body/ytd-app/div[1]/ytd-page-manager/ytd-watch-flexy/div[5]/div[1]/div/div[2]/ytd-engagement-panel-section-list-renderer[4]/div[2]/ytd-transcript-renderer/div[2]/ytd-transcript-search-panel-renderer/div[2]/ytd-transcript-segment-list-renderer""")
    print(element.text)

    text = element.text

    z = open('test.txt', 'w')
    z.write(text)
    z.close

    g = open('prov.txt', 'w')
    g.write("sss")
    g.close

except:
    print("111")




